/*
 *                       core_mod.h
 *
 *   Core Modules header file and Cross Module Services Functions.
 */

#ifndef _CORE_MOD_H_
#define _CORE_MOD_H_

#include "utils_conf.h"

#define		FMVER_YMD(y,m,d)  	((y<<16) | (m<<8) | (d))
#define		Y_FMVER(fmver)		(fmver>>16)
#define		M_FMVER(fmver)		((fmver>>8) & 0xFF)
#define		D_FMVER(fmver)		(fmver & 0xFF)

typedef struct tagFilterModule {
	int			check_size;
	int			version;

	char			*name;
	char			*description;
	int			status;

	int			(*initialize)( void );	// Module initialization
	int			(*post_init)( void );	// 2'nd stage initial (invoked after all module is initialize)
	int			(*terminate)( void );	// terminate
	int			(*post_term)( void );  	// 2'nd stage termination (invoked after all modules is terminate)

	/* read only reference */
	ConfUnit		*conf;

} FilterModule;

extern int CORE_initialize_modules( ConfUnit * conf );
extern int CORE_post_initialize_modules( void );
extern int CORE_terminate_modules( void );

/* module status */
#define MOD_STATUS_ERROR	-1	// Error and stop
#define MOD_STATUS_FRESH	0	// A fresh copy not inited.
#define MOD_STATUS_RUNNING	1	// working normally
#define MOD_STATUS_CLOSING	2	// terminating now
#define MOD_STATUS_CLOSED	3	// read to be unload

/* [ C r o s s M o d u l e F u n c ] */
// function prototype of cross module servicies functions.
#define CMSF_USERLOGIN		0	// Argument: ( const char *user_name, const char *password, GroupProfile **group );	// return UserProfile * (NULL if invalid). And group will be pointed to the group structure that this user is belongs to
#define CMSF_STARTSTREAM	1	// Argument: ( StreamRequestor * )
#define CMSF_STARTRECORD	2	// Argument: ( const char *vid, int method, int pre_sec, int nsec, const char *source)
#define CMSF_STOPRECORD		3	// Argument: ( const char *vid, int method, const char *source)
#define CMSF_SETVALUE		4	// Argument: ( PointId *point, int value );
#define CMSF_GETVALUE		5	// Argument: ( PointId *point );
#define CMSF_SETFAILED		6	// Argument: ( PointId *point, int fail );
#define CMSF_VDSETVALUE		7	// Argument: ( int point_type, int point_port, int value )	// Virtual Device SetValue
#define CMSF_VDGETVALUE		8	// Argument: ( int point_type, int point_port )			// return point value
#define CMSF_CHECKINSCHEDULE	9	// Argument: ( PointId *point );	// Check if Point is in schedule now
#define CMSF_PTZCTRL		10	// Argument: ( PointId *point, int param );
#define CMSF_PTZTEXTCMD		11	// Argument: ( char *cmdtext );
#define CMSF_PTZGETPROTOCOL	12	// Argument: ( PointId *point, char *buf )
#define CMSF_VIDEOCTRL		13	// Argument: ( int port, int color, int hue, int brightness, int contrast );  // all in %
#define CMSF_MOTIONCTRL		14	// Argument: ( int port, int code, ... );
#define CMSF_GETUSERGROUP	15	// Argument: ( int *ngroup, GroupProfile **group, int *nuser, UserProfile **user );
#define CMSF_GETSTREAMUSER	16	// Argument: ( int fd, GroupProfile **group ) 		fd is the stream socket
#define CMSF_GETRECORDER	17	// Argument: ( NULL ): cast return to UMFRecordingManager
#define CMSF_SETPDPVALUE	18	// Argument: ( int port, int n, int value );	// n is 1 ~ 4. for DI/CAMERA point extra status such as recording now.
#define CMSF_GETCAMERASTATUS	19	// Argument: ( char *staus )

 /* code of CMSF_MDCTRL */
#define MDCTRL_CODE_ONOFF	1	// On/Off the motion detection  ( int port, int code, int onoff )
#define MDCTRL_CODE_SENSITIVITY	2	// Set sensitivity ( int port, int code, int sensitivity )  (1 ~ 10)
#define MDCTRL_CODE_DRAWAREA	3	// Turn on/off the detection area ( port, code, onoff )
#define MDCTRL_CODE_DRAWTARGET  4	// Draw detected target or not (port, code, yesno )
#define MDCTRL_CODE_AREACLEAN	5	// Remove all detection area (port, code)
#define MDCTRL_CODE_AREAADD	6	// add a detection area ( port, code, type <0:mask/1:window>, left, top, right, bottom )

typedef	int    (*_cms_func_t)( void *, ... );

extern int		CMSF_register( int code, _cms_func_t func );
extern int		CMSF_unregister( int code );
extern _cms_func_t	CMSF_find( int code );


#endif /* _CORE_MOD_H_ */
